﻿using System;
using System.Configuration;
using LogLibrary.Entity;
using LogLibrary.Implementation;

namespace LogLibrary
{
    public class Logger
    {
        private readonly LogService _logService;

        public Logger()
        {
        }

        public Logger(Type logClass)
        {
            LogConnectionInfo.SqlConnectionString = ConfigurationManager.ConnectionStrings["LoggerDatabaseContext"].ConnectionString;
            //LogConnectionInfo.LogFileLocation = ConfigurationManager.AppSettings["InternalLogFileLocation"];
            _logService = new LogService(logClass);
        }

        public Logger(Type logClass,string logFileName)
        {
            LogConnectionInfo.SqlConnectionString = ConfigurationManager.ConnectionStrings["LoggerDatabaseContext"].ConnectionString;
          //  LogConnectionInfo.LogFileLocation = logFileName;
            _logService = new LogService(logClass);
        }

        public void Log(LogType logType, LogServiceInformation logServiceInfo)
        {
            log4net.GlobalContext.Properties["LogServiceInformation"] = logServiceInfo;
            switch (logType)
            {
                case LogType.INFO: _logService.Info(logServiceInfo); break;
                case LogType.DEBUG: _logService.Debug(logServiceInfo); break;
                case LogType.ERROR: _logService.Error(logServiceInfo); break;
                case LogType.FATAL: _logService.Fatal(logServiceInfo); break;
                case LogType.WARN: _logService.Warn(logServiceInfo); break;
            }
        }
    }
}
